﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TestFrameworkExtension
{
    
    
    /// <summary>
    ///这是 EnumExtensionTest 的测试类，旨在
    ///包含所有 EnumExtensionTest 单元测试
    ///</summary>
    [TestClass()]
    public class EnumExtensionTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///ToChineseDescription 的测试
        ///</summary>
        [TestMethod()]
        public void ToChineseDescriptionTest()
        {
            var customerInfo = new CustomerInfo();
            var info = customerInfo.GetExpressionText(m => m.UserName);
            var chin = new ChineseDescriptionAttribute("");
            var a = TypeDescriptor.GetAttributes(chin, true);
            var attr = (typeof (CustomerInfo).GetCustomAttributes(typeof (ChineseDescriptionAttribute), true)[0]);
            var ok = ((ChineseDescriptionAttribute) attr).Text;
            Enum status = ReponseStatus.Success;
            string expected = "成功";
            string actual = status.ToChineseDescription();
            if (!Enum.IsDefined(typeof(ReponseStatus), status))

            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
    }
    public class CustomerInfo
    {
        [ChineseDescription("用户名")]
        public string UserName { get; set; }
        
        [ChineseDescription("密码")]
        public string Password { get; set; }
    }
    public enum ReponseStatus
    {
        [ChineseDescription("成功")]
        Success = 1,

        [ChineseDescription("错误")]
        Error = 2,

        Unknown = 3,

        [ChineseDescription("失败")]
        Fail = 4
    }
}
